package com.hnust.controller;

import com.hnust.entity.dto.DeviceDto;
import com.hnust.entity.dto.PositionDto;
import com.hnust.entity.dto.TreeNodeDto;
import com.hnust.service.PositionService;
import com.hnust.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/5/6
 * 描述：
 */
@Slf4j
@RestController
@RequestMapping("/position")
@CrossOrigin("*")
public class PositionController {
    @Autowired
    private PositionService positionService;
    @GetMapping("/list")
    public R<List<PositionDto>> positionList(){
        List<PositionDto> positionDtos=positionService.positionList();
        return R.success(positionDtos);
    }

    @GetMapping("/list/tree")
    public R<List<TreeNodeDto>> positionTreeList(){
        List<TreeNodeDto> treeNodeDtos=positionService.positionTreeList();
        return R.success(treeNodeDtos);
    }

    @GetMapping("/list_device")
    public R<List<DeviceDto>> positionListDevice(
            Integer regionCode,Integer buildCode,
            Integer floorCode,Integer roomCode
    ){
        List<DeviceDto> deviceDtos=positionService.positionListDevice(
                regionCode,buildCode,floorCode,roomCode
        );
        return R.success(deviceDtos);
    }

    @GetMapping("/list_positionId")
    public R<List<String>> positionCodeToList(Integer regionCode,Integer buildCode,
                                              Integer floorCode,Integer roomCode)
    {
        List<String> positionCodeToLists=positionService.positionCodeToList(
                regionCode,buildCode,floorCode,roomCode
        );
        return R.success(positionCodeToLists);
    }
}
